/* Copyright (C) 2010 Luca Piccinelli
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/* 
 * File:   CameraInputGenerator.h
 * Author: lpiccinelli
 *
 * Created on 17 agosto 2010, 21.51
 */

#ifndef CAMERAINPUTGENERATOR_H
#define	CAMERAINPUTGENERATOR_H

#include <vector>

#include <cv.h>
#include <highgui.h>

#include "gestface.h"
#include "generators/generators.h"
#include "exceptions/camera_exceptions.h"

namespace NAMESPACE{

class CameraInputGenerator : public AbstractGenerator{
public:
    typedef int capture_t;

    const static capture_t DEFAULT_CAPTURE;

    using AbstractGenerator::generate;
    using AbstractGenerator::set_key;
private:
    cv::Size sz;
    cv::VideoCapture* capture;

    capture_t capture_num;

    bool is_open;

    virtual void free_element(IOElement* el);
    virtual memory_size_t measure_memory();
public:    
    ~CameraInputGenerator();
    CameraInputGenerator();
    CameraInputGenerator(const CameraInputGenerator& cig);
    CameraInputGenerator& operator=(const CameraInputGenerator& cig);

    CameraInputGenerator(const IOKey& k,
                         const capture_t& _capture_num = DEFAULT_CAPTURE,
                         const memory_size_t& _max_mem = AbstractGenerator::DEFAULT_MAX_MEM_SIZE);
    CameraInputGenerator(const IOKey& k,
                         const size_t width,
                         const size_t height,
                         const capture_t& _capture_num,
                         const memory_size_t& _max_mem = AbstractGenerator::DEFAULT_MAX_MEM_SIZE);

    virtual Generator& set_key(const std::string& ns, const std::string& key_name);
    CameraInputGenerator& set_capture_num(const capture_t& _capture_num);
    
    const capture_t& get_capture_num() const;

    bool is_opened() const;

    CameraInputGenerator& open() throw (bad_video_capture);
    CameraInputGenerator& close();

    IOElement* generate(const IOKey& key);

    virtual bool operator==(const Generator& cig) const;
    virtual bool operator!=(const Generator& cig) const;
};

}

#endif	/* CAMERAINPUTGENERATOR_H */

